path = "/var/www/cgi-bin/r/modules/calc_portfolio_performance.r"

print ( path )
source( path )


#	正常系のテスト
test_calc_portfolio_000 <- function()
{
	print( "test case 000" )

	means <- c( 0.12, 0.15 )
	variances <- c( 0.20, 0.18 )
	covariances <- matrix( nrow=2, ncol=2 )
	covariances[ 1, 1 ] <- 0.2^2
	covariances[ 1, 2 ] <- 0.01
	covariances[ 2, 1 ] <- 0.01
	covariances[ 2, 2 ] <- 0.18^2
	ratio <- c( 0.25, 0.75 )

	res <- calc_portfolio_performance( means, variances, covariances, ratio )
#	print( res )
	if ( round( res$mean, 4 ) != 0.1425 )
	{
		cat( "expect: res$mean != 0.1425, res$mean:", res$mean, "\n" )
	}
	if ( round( res$variance, 6 ) != 0.024475 )
	{
		cat( "expect: res$variance != 0.024475, res$variance:", res$variance, "\n" )
	}
}

# 異常系のテスト
test_calc_portfolio_001 <- function()
{
	print( "test case 001" )
	
	means <- c( 0.12, 0.15 )
	variances <- c( 0.20, 0.18 )
	covariances <- matrix( nrow=2, ncol=2 )
	covariances[ 1, 1 ] <- 0.2^2
	covariances[ 1, 2 ] <- 0.01
	covariances[ 2, 1 ] <- 0.01
	covariances[ 2, 2 ] <- 0.18^2
	ratio <- c( 0.25, 0.75, 0.0 )		# data count error

	res <- calc_portfolio_performance( means, variances, covariances, ratio )
	if ( is.null( res$error_message ) )
	{
		cat( "expect: res$error_message != NULL, NULL ", "\n" )
	}
}

#	run test
test_calc_portfolio_000()
test_calc_portfolio_001()
